/**
  ******************************************************************************
  * File Name          : tskctrl.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "bsp.h"
#include "tskcfg.h"
#include "cmos.h"
#include <string.h>
/*------------ task define ------------*/

TaskHandle_t xRunDog_Thd = NULL;
StaticTask_t xRunDog_Tcb;
StackType_t  xRunDog_Stk[RUNDOG_STACK_SIZE];

TaskHandle_t xKey_Thd = NULL;
StaticTask_t xKey_Tcb;
StackType_t  xKey_Stk[KEY_STACK_SIZE];

/**
  * @brief  Create task
  * @param  None
  * @retval None
  */
void APP_CreateTask(void)
{
	xRunDog_Thd = xTaskCreateStatic(vRunDog_Task,
	                                 "RunD",
	                                 RUNDOG_STACK_SIZE,
	                                 (void *)1,
																	 RUNDOG_TSK_PRIORITY,
																	 xRunDog_Stk,
																	 &xRunDog_Tcb);
                                   
	xKey_Thd = xTaskCreateStatic(vKey_Task,
                               "key",
                               KEY_STACK_SIZE,
                               (void *)1,
                               KEY_TSK_PRIORITY,
                               xKey_Stk,
                               &xKey_Tcb);

	xCmos_Thd = xTaskCreateStatic(vCmos_Task,
                                "cmos",
                                CMOS_STACK_SIZE,
                                (void *)1,
                                CMOS_TSK_PRIORITY,
                                xCmos_Stk,
                                &xCmos_Tcb);
                                   
//  xTerminal_Thd  = xTaskCreateStatic(vTerminal_Task,
//																	   "term",
//																	   TTY_STACK_SIZE,
//																	   (void *)1,
//																	   TTY_TSK_PRIORITY,
//																	   xTerminal_Stk,
//																	   &xTerminal_Tcb);
}

void APP_CreateRunTimeTask(void)
{
}

void vRunDog_Task(void * pvParameters)
{
  uint8_t step = 0;
  
	while(1)
	{
    vTaskDelay(1000);
    
    Sys_GetDataTime();
    
//    LED1_Toggle();
//    LED2_Toggle();
//    LED3_Toggle();
    
    if(step >= 10)
    {
//      LL_IWDG_ReloadCounter(IWDG);
      step = 0;
    }
    
    step++;
	}
}

void vKey_Task(void * pvParameters)
{
	while(1)
	{
    if(ulTaskNotifyTake(pdTRUE, portMAX_DELAY) != 0)
    {
      vTaskDelay(30);
      if(WakeUpKey2() != 0)
      {
        vTaskDelay(30);
        if(WakeUpKey2() != 0)
        {
          if(Cmos_Cmd_qhd != NULL)
          {
            xQueueSend(Cmos_Cmd_qhd, &Cmos_CmdStartCapture, 0);
          }
        }
      }
    }
	}
}

/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );

/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];

void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
  *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  *ppxIdleTaskStackBuffer = &xIdleStack[0];
  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}

/* Private application code --------------------------------------------------*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
